// -----------------------------------------------------------------------
// <copyright file="BasePage.cs" company="Imar.Spaanjaars.Com">
//   Copyright 2008 - 2009 - Imar.Spaanjaars.Com. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;

namespace Spaanjaars.ContactManager.Web
{
	/// <summary>
	/// Serves as the local BasePage class for all pages in the Contact Manager Application.
	/// </summary>
	public class BasePage : Page
	{
		protected override void InitializeCulture()
		{
			// Try to find the language preference cookie and set the Culture accordingly.
			try
			{
				if (Request.Cookies.Get("PrefLang") != null && !string.IsNullOrEmpty(Request.Cookies.Get("PrefLang").Value))
				{
					string userCulture = Request.Cookies.Get("PrefLang").Value;
					if (!string.IsNullOrEmpty(userCulture))
					{
						// there is a user language setting in a cookie: switch to it
						Thread.CurrentThread.CurrentUICulture = new CultureInfo(userCulture);
						Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(userCulture);
					}
				}
			}
			catch
			{
				// Clear the cookie in case there's a problem
				Request.Cookies.Remove("PrefLang");
			}
		}
	}
}